﻿using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Domain.Interface.IColumnManagement;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IntelligentAgriculture.Domain.Impl.ColumnManagementRepository  
{
    public class ColumnRepository : IColumnManRepository
    {
        public readonly AgricultureDbContext _context;
        public ColumnRepository(AgricultureDbContext context)
        {
            _context = context;
        }
       
        /// <summary>
        /// 栏位添加功能
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>返回受影响行数</returns>
        public Task<int> Add(Columnmanagement entity)
        {
            try
            {
                _context.Add(entity);
                return _context.SaveChangesAsync();
            }
            catch (Exception)
            {

                throw;
            }
        }

        public IQueryable<Columnmanagement> GetShow()
        {
            return _context.Columnmanagements.AsQueryable().AsNoTracking();
        }
		/// <summary>
		/// 根据栋舍获取栏位列表
		/// </summary>
		/// <returns></returns>
		public async Task<IQueryable<Columnmanagement>> GetColumnManagement(int ridgepoleId)
		{
			var list = _context.Columnmanagements.Where(c => c.RidgepoleId == ridgepoleId).AsQueryable();
			return list;
		}
	}
}
